package cn.com.gdut.ppj.hr.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import cn.com.gdut.ppj.common.dao.ICandidateRecruitmentInfoDao;
import cn.com.gdut.ppj.common.dao.IOtherSelectDao;
import cn.com.gdut.ppj.hr.dao.ICompanyDao;
import cn.com.gdut.ppj.hr.dao.IHrDao;
import cn.com.gdut.ppj.hr.service.IHrService;
import cn.com.gdut.ppj.model.TbCandidateRecruitmentInfo;
import cn.com.gdut.ppj.model.TbCompany;
import cn.com.gdut.ppj.model.TbHr;
import cn.com.gdut.ppj.model.TbRecruitmentInformation;
import cn.com.gdut.ppj.model.TbResume;
import cn.com.gdut.ppj.model.TbUser;
import cn.com.gdut.ppj.user.dao.IRecruitmentInformationDao;
import cn.com.gdut.ppj.vo.HrResumeViewVO;

@Service("hrService")
public class HrServiceImpl implements IHrService {
	
	@Resource private IHrDao hrDao;
	@Resource private ICompanyDao companyDao;
	@Resource private IRecruitmentInformationDao riDao;
	@Resource private IOtherSelectDao otherDao;
	@Resource private ICandidateRecruitmentInfoDao crDao;

	@Override
	public List<TbCandidateRecruitmentInfo> selectCandidateRecruitmentInfo(TbCandidateRecruitmentInfo tcri) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TbCandidateRecruitmentInfo updateCandidateRecruitmentInfo(TbCandidateRecruitmentInfo tcri) {
		Integer tem = crDao.updateCandidateRecruitmentInfoByCriId(tcri);
		if(tem > 0){
			return tcri;
		}
		return null;
	}

	@Override
	public List<TbResume> selectResume(TbResume resume) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TbCompany addCompany(TbCompany company) {
		Integer tem = companyDao.insertCompany(company);
		if(tem > 0){
			return company;
		}
		return null;
	}

	@Override
	public TbCompany updateCompany(TbCompany company) {
		TbCompany tem = companyDao.selectCompanyById(company);
		if(null == tem){
			return null;
		}else{
			companyDao.updateCompanyById(company);
		}
		return company;
	}

	@Override
	public TbCompany selectCompanyByHrId(TbCompany company) {
		TbCompany tem = companyDao.selectCompanyByHrId(company);
		return tem;
	}

	@Override
	public TbHr addHr(TbHr hr) {
		Integer tem = hrDao.insertHr(hr);
		if(tem > 0){
			return hr;
		}
		return null;
	}

	@Override
	public TbHr updateHr(TbHr hr) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TbHr selectHrByUserId(TbHr hr) {
		TbHr tem = hrDao.selectHrByUserId(hr);
		return tem;
	}

	@Override
	public TbRecruitmentInformation addRecruitmentInformation(TbRecruitmentInformation tri, TbUser user) {
		TbHr hr = new TbHr();
		hr.setUserId(user.getUserId());
		hr=hrDao.selectHrByUserId(hr);
		if(hr == null){
			return null;
		}
		tri.setCompanyId(hr.getCompanyId());
		Integer result = riDao.insertRecruitmentInformation(tri);
		if(result > 0){
			return tri;
		}
		return null;
	}

	@Override
	public TbRecruitmentInformation updateRecruitmentInformation(TbRecruitmentInformation tri) {
		Integer tem = riDao.updateRecruitmentInformationById(tri);
		if(tem > 0){
			return tri;
		}
		return null;
	}

	@Override
	public TbRecruitmentInformation deleteRecruitmentInformation(TbRecruitmentInformation tri) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<TbRecruitmentInformation> selectRecruitmentInformation(TbRecruitmentInformation tri) {
		List<TbRecruitmentInformation> tem = riDao.selectRecruitmentInformationBy(tri);
		return tem;
	}

	/**
	 * 进行事务管理
	 */
	@Override
	@Transactional
	public Integer addHrAndComapny(TbHr hr, TbCompany company) throws Exception {
		this.addCompany(company);
		this.addHr(hr);
		return 1;
	}

	@Override
	public TbCompany selectCompanyById(TbCompany company) throws Exception {
		company = companyDao.selectCompanyById(company);
		return company;
	}

	@Override
	public List<HrResumeViewVO> hrResumeView(TbCandidateRecruitmentInfo cri) throws Exception {
		List<HrResumeViewVO> list = otherDao.hrResumeView(cri);
		return list;
	}

	@Override
	public List<TbRecruitmentInformation> selectRecruitmentInformationPage(Map<String, String> hash, Integer num)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer countRecruitmentInformation(Map<String, String> hash) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
